<?php

namespace app\api\controller;

use app\BaseController;

class SocketService extends BaseController
{
    public function websocket($channel, $content)
    {
        $url = 'https://rest-hz.goeasy.io/v2/pubsub/publish';
        $data = array(
            'appKey' => 'BC-dff786e36e7a45fda5fbac736947d7c3',
            'channel' => $channel,
            'content' => $content,
        );
        $options = array(
            'http' => array(
                'header' => "Content-type: application/x-www-form-urlencoded\r\n",
                'method' => 'POST',
                'content' => http_build_query($data)
            )
        );
        $context = stream_context_create($options);
        $result = file_get_contents($url, false, $context);
        if ($result === false) {
            return false;
        }
        return $result;
    }
}